package DesignPatern.A15_组合模式.QSB.A01_基本模式;

import java.util.ArrayList;

/**
 * @Author: Du
 * @Date: 2021/8/2 9:47
 */
public class A01_Main
{
    public static void main(String[] args)
    {
        IRoot ceo = new Root("zs", "总经理", 90000);
        
        IBranch devDep = new Branch("ls", "财务总经理", 10000);
        IBranch salDep = new Branch("ww", "市场总经理", 20000);
        IBranch fianceDep = new Branch("zl", "研发总经理", 30000);
        
        ILeaf a = new Leaf("a", "财务1", 1111);
        ILeaf b = new Leaf("b", "财务2", 2222);
        ILeaf c = new Leaf("c", "财务3", 3333);
        ILeaf d = new Leaf("d", "市场1", 1111);
        ILeaf e = new Leaf("e", "市场2", 2222);
        ILeaf f = new Leaf("f", "市场3", 3333);
        ILeaf g = new Leaf("g", "开发1", 1111);
        ILeaf h = new Leaf("h", "开发2", 2222);
        ILeaf i = new Leaf("i", "开发3", 3333);
        
        ceo.add(devDep);
        ceo.add(salDep);
        ceo.add(fianceDep);
        
        devDep.add(a);
        devDep.add(b);
        devDep.add(c);
        
        salDep.add(d);
        salDep.add(e);
        salDep.add(f);
        
        fianceDep.add(g);
        fianceDep.add(h);
        fianceDep.add(i);
        
        System.out.println(ceo.getInfo());
        getAllSubInfo(ceo.getSubInfo());
        
    }
    
    public static void getAllSubInfo(ArrayList subInfo)
    {
        int length = subInfo.size();
        
        for (int i = 0; i < length; i++)
        {
            Object o = subInfo.get(i);
            if (o instanceof Leaf)
            {
                ILeaf employee = (ILeaf) o;
                System.out.println(employee.getInfo());
            } else
            {
                IBranch employee = (IBranch) o;
                System.out.println(employee.getInfo());
                getAllSubInfo(employee.getSubList());
            }
        }
    }
}
